/*
 * $HeadURL: $
 * $Id: $
 * Copyright (c) 2011 by Ericsson, all rights reserved.
 */

package android.views;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

/**
 *
 * @author xyonton
 * @version $Revision: $
 */
public class ImageAdapter extends BaseAdapter {
    private Context               mContext;

    private Bitmap                bmp;

    private BitmapFactory.Options options = new BitmapFactory.Options();

    //    // references to our images
    //    public static Integer[] mThumbIds = { R.drawable.background };

    // Get our images
    public static List<String>    imageList;

    public ImageAdapter(Context c, List<String> li) {
        mContext = c;
        imageList = li;
    }

    public int getCount() {
        //        return mThumbIds.length;
        return imageList.size();
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if (convertView == null) { // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
            //            imageView.setAdjustViewBounds(true);
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(8, 8, 8, 8);
        } else {
            imageView = (ImageView) convertView;
        }

        options.inSampleSize = 10;

        try {
            bmp = BitmapFactory.decodeFile(imageList.get(position), options);
        } catch (OutOfMemoryError err) {
            System.out.println(err.toString());
        }

        //    	bmp= BitmapFactory.decodeFile(imageList.get(position),options);
        //        bmp = BitmapFactory.decodeFile(imageList.get(position));

        imageView.setImageBitmap(bmp);

        return imageView;
    }
}
